Announcement Announcement Module
Collapse
No announcement yet.
Navigating an AbstractWizardFormController with an anchor tag Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Navigating an AbstractWizardFormController with an anchor tag

    Hi to all,

    How can I navigate to another page using an anchor tag?
    I can very easily navigate to the second page of the AbstractWizardFormController with the following code:
    Code:
    <input type="submit" name="_target1"/ value="<fmt:message key="edit"/>">
    because of this:
    The target page for page changes can be specified by PARAM_TARGET, appending the page number to the parameter name (e.g. "_target1"). The action parameters are recognized when triggered by image buttons too (via "_finish.x", "_abort.x", or "_target1.x").
    but I need a link instead of a button. I thought this could solve the problem:
    jsp:
    Code:
    <a href="" onclick="submitFormWithAdditionalCustomParameter('hiddenTargetParameterHolderId', '_target1', 'orderForm', '');">
    	<fmt:message key="order.payment.review.edit"/>
    </a>
    <input type="hidden" id="hiddenTargetParameterHolderId" name="" value="true"/>
    javascript:
    Code:
    function submitFormWithAdditionalCustomParameter(idOfHiddenField, nameOfParameter, nameOfForm, idOfForm)
    {
    	
    	var hiddenElement = document.getElementById(idOfHiddenField);
    	hiddenElement.name = nameOfParameter;
    	//submit the form
    	if (idOfForm == null || idOfForm == ''){//no id specified
    		var elements = document.getElementsByName(nameOfForm);
    		//need to check if it is the form we are submitting:
    		var form = elements[0];
    		form.submit();
    	}else{
    		document.getElementById(idOfForm).submit();
    	}
    	//we don't want the default action of the field (where this function was called) 
    	//to be executed. 
    	return false;
    }
    I debugged and the javascript works (it changes the name of the input hidden field to "_target1" and gets the needed form and submits it). But in the wizard controller he comes to the formBackingObject method (goes to the first page - page[0]). The wizard controller is below:

    Code:
    public class OrderProcessWizardController extends AbstractWizardFormController {
    
    	OrderService orderService = null;
    
    	public void setOrderService(OrderService orderService) {
    		this.orderService = orderService;
    	}
    
    	RegistrationService registrationService = null;
    
    	public void setRegistrationService(RegistrationService registrationService) {
    		this.registrationService = registrationService;
    	}
    
    	CartServiceImpl cartServiceImpl = null;
    
    	public void setCartServiceImpl(CartServiceImpl cartServiceImpl) {
    		this.cartServiceImpl = cartServiceImpl;
    	}
    
    	public OrderProcessWizardController() {
    		setCommandClass(OrderBackingObject.class);
    		setCommandName("orderBackingObject");
    	}
    
    	protected Object formBackingObject(HttpServletRequest request)
    			throws ModelAndViewDefiningException {
    		ShoppingCart shoppingCart = (ShoppingCart) WebUtils
    				.getSessionAttribute(request, "scopedTarget.shoppingCart");
    		if (shoppingCart != null) {
    			// Re-read account from DB at team's request.
    			RudimentedUser rudimentedUser = (RudimentedUser) WebUtils
    					.getSessionAttribute(request, "scopedTarget.rudimentedUser");
    			if (rudimentedUser == null){
    				rudimentedUser = (RudimentedUser) WebUtils
    				.getSessionAttribute(request, "rudimentedUser");
    			}
    			User user = registrationService
    					.getUserForRudimentedUserId(rudimentedUser.getId());
    			Map<Long, ShippingMethod> shippingMethodsList = cartServiceImpl
    					.getShippingMethodsMap();
    			PaymentInfo paymentInfo = orderService.getPaymentInfo();
    			OrderBackingObject orderBackingObject = new OrderBackingObject(
    					user, shippingMethodsList, 1, false,
    					paymentInfo, new Date(), shoppingCart
    							.getTotalPriceInDollarsWithoutDollar(), shoppingCart);
    
    			return orderBackingObject;
    		} else {
    			ModelAndView modelAndView = new ModelAndView("Error");
    			modelAndView
    					.addObject("message",
    							"An order could not be created because a cart could not be found.");
    			throw new ModelAndViewDefiningException(modelAndView);
    		}
    	}
    
    	@Override
    	protected ModelAndView processFinish(HttpServletRequest request,
    			HttpServletResponse response, Object command, BindException errors)
    			throws Exception {
    		OrderBackingObject orderBackingObject = (OrderBackingObject) command;
    		orderService.insertOrder(orderBackingObject);
    		request.getSession().removeAttribute("sessionCart");
    		Map<String, Object> model = new HashMap<String, Object>();
    		model.put("order", orderBackingObject);
    		model.put("message", "Thank you, your order has been submitted!");
    		return new ModelAndView(getSuccessView(), model);
    	}
    
    	// returns the last page as the success view
    	private String getSuccessView() {
    		return getPages()[getPages().length - 1];
    	}
    
    	protected ModelAndView processCancel(HttpServletRequest request,
    			HttpServletResponse response, Object command,
    			BindException bindException) throws Exception {
    		return new ModelAndView(getSuccessView());
    	}
    	
    	protected void validatePage(Object command, Errors errors, int page) {
    		OrderBackingObject orderBackingObject = (OrderBackingObject) command;
    		OrderProcessValidator orderProcessValidator = (OrderProcessValidator) getValidator();
    		switch (page) {
    			case 0:
    orderProcessValidator.validate(orderBackingObject.getUser(), errors);
    				break;
    			case 1:
    				orderProcessValidator.validateAgreeShippingPrivacyReturnPolicy(orderBackingObject.isAgreedToShippingReturnPrivacyPolicies(), errors);
    				break;
    			case 2:
    				orderProcessValidator.validateCreditCard(orderBackingObject.getPaymentInfo(), errors);
    				break;
    			case 3:
    				break;
    		}
    	}
    	
    	protected int getTargetPage(HttpServletRequest request, Object command, Errors errors, int currentPage) {
    		return super.getTargetPage(request, command, errors, currentPage);
    	}
    the configuration part for the order wizard controller:
    Code:
    	<!-- ORDER PROCESS WIZARD CONTROLLER -->
    	<bean name="/checkout.htm" id="orderProcessWizardController"
    		class="checkout.OrderProcessWizardController">
    		<property name="orderService" ref="orderService" />
    		<property name="registrationService" ref="registrationService" />
    		<property name="cartServiceImpl" ref="cartServiceImpl"/>
    		<property name="pages">
    			<list>
    				<value>customerDetail</value>
    				<value>shipping</value>
    				<value>payment</value>
    				<value>confirmOrder</value>
    				<value>redirect:/home.htm</value>
    			</list>
    		</property>
    		<property name="validator">
    			<bean class="checkout.OrderProcessValidator" />
    		</property>
    	</bean>
    	<bean id="orderService" class="checkout.OrderService">
    		<property name="orderDB" ref="orderDB"/>
    	</bean>
    	<bean id="orderDB" class="mockup.OrderDB"/>
    Is there any way of sending the _target1 parameter? Does the controller recognize the _target1 from the request? Where can I find the "_target1" parameter? When I was debugging it seemed like this parameter was deleted from the request. Can anyone tell me what I am doing wrong? Or at least give me some tip.

    Kind Regards,
    despot

  • #2
    Can anyone please comment on anything?
    Perhaps, some of you moderators knows something!? Even an "I haven't encountered this kind of problem..." would be cool.
    despot

    Comment

    Working...
    X