Prevent redirect with Ajax commandLink

Splash Forums PrettyFaces Users Prevent redirect with Ajax commandLink

Tagged: ,

This topic contains 5 replies, has 3 voices, and was last updated by  Lincoln Baxter III 1 year, 6 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #26829

    JamesPP
    Participant

    The following example: an employee has many phone numbers. on click on the “+” commandLink, the section of the form with the phone number list should be new renderd (the goal is to add a new input form element to the form).
    But after the ajax request the page will be redirect to the url of the commanLink /employee/update/101/phone/addnew/
    Does anybody know why? Or any other idea to do it?
    Hier my way how to do that:

    
    @Named
    @SessionScoped
    public class EmployeeController  implements Serializable { 
    	private final Employee emp;
    	
    	public String addPhoneNumber() {
    		emp.getPhonenumbers().add(new PhoneNumber());
    		return null;
    	}
    }
    
    
    <url-mapping id="add_new_phonenr">
    	<pattern value="/employee/update/#{ /(\\d+)/ empId : employeeController.emp.oid }/phone/addnew/" />
    	<view-id value="/employee.xhtml" />
    	<action>#{employeeController.addPhoneNumber}</action>
    </url-mapping>
    
    <div class="form-group">
    	...
    	<div class="col-sm-1">
    		<h:commandLink action="pretty:add_new_phonenr">
    			<f:param value="#{employeeController.emp.oid}" />
    			<mr:glyphicon icon="glyphicon-plus" title="..." />
    			<f:ajax render="myform:phnoenrsection" />
    		</h:commandLink>
    	</div>
    </div>
    • This topic was modified 1 year, 6 months ago by  JamesPP.
    #26831

    You are using a command link with action="pretty:add_new_phonenr". An action outcome of pretty:whatever will always result in a redirect. Why are you using this outcome?

    #26832

    JamesPP
    Participant

    Srry, please read the next reply.
    ————————————–

    I just want to call the action “#{employeeController.addPhoneNumber}” and rerendering the specific form section. And it will be great to do that in the prettyfaces url-mapping. Because I just want, taht my application also works fine if there is no JS.
    Do you have an idea how to do? Or there is no way expect to use JS.

    Thank you.

    • This reply was modified 1 year, 6 months ago by  JamesPP.
    #26833

    JamesPP
    Participant

    I just want to call the action “#{employeeController.addPhoneNumber}” and rerendering the specific form section. And it will be great to do that in the prettyfaces url-mapping. Because there other action calls like ““#{employeeController.isAllowedToDoThat}”” before to add a new PhoneNumber Object and I just want, taht my application also works fine wothout JS.
    Do you have an idea how to do? Or there is no way expect to use JS.

    Thank you.

    #26835

    Making your JSF app to work correctly without JavaScript is a VERY difficult task. And I personally doubt that JSF is a good framework for such a requirement. I recommend to start implementing this requirement WITHOUT Rewrite. And if you got it working, you can add Rewrite later on.

    #26853

    As Christian says, there’s really no way to do partial page rendering (rendering a single form in a page) without using JavaScript. You’d have to request the entire page again.

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.

Comments are closed.