A bit of help with struts tags please

Hi, i am using struts tags for check box

I am using struts for my web application. So when i click on a button i make a select on the data base, the object obtained is set in session and a page opens. On that page i have some check boxes which i want them to be checked when the page is loaded. With input works because it has checked property but html:checkbox doesn't has that property

So here is the jsp code:

<%@ include file="taglibs.jsp" %>

<jsp:useBean id = "currentBean" scope="session" type="orderInfo.OrderInfoBean"/>

<html>

<head>

bla bla

</head>

<body>

<html:form action="/editOrder.do" method="post">

<table>

<tr>

<td>Package

<%if(currentBean.getPackageNo() > 0){ %>

<html:checkbox property="coletCheckbox" value="true"></html:checkbox>

<%} %>

<%if(currentBean.getPackageNo()==0){ %>

<html:checkbox property="coletCheckbox" value="false"></html:checkbox>

<%} %>

</td>

</tr>

</table>

</html:form>

</body>

</html>

thanks in advance

David

[1270 byte] By [Ichybana] at [2007-11-27 5:45:25]
# 1

[nobr]I had got the same answer from a different link....so passing u the details :

Whether it is checked or not is determined by the associated property.

code:

--

<HTML>

<HEAD>

<TITLE><bean:message key="title.login" /></TITLE>

</HEAD>

<BODY><struts:message key="heading.login" /><html:errors />

<html:form action="/login">

<bean:message key="label.userId" />:<html:text property="userId" size="10" /><br>

<bean:message key="label.passWord" />:<html:password property="passWord" size="10" />

<br><br>Save Info: <html:checkbox property="saveInfo" />

<br><br>

<html:submit><bean:message key="button.submit" /></html:submit>

</html:form>

</BODY>

</HTML>

--

If I want the "save info" checkbox checked then all I need to do is this in my form:

code:

--

package test.struts;

import org.apache.struts.action.*;

import javax.servlet.http.*;

public class LoginForm extends ActionForm {

String userId, passWord;

boolean saveInfo = true;

public void setUserId(String userId) {

this.userId = userId;

}

public void setPassWord(String passWord) {

this.passWord = passWord;

}

public void setSaveInfo(boolean saveInfo) {

this.saveInfo = saveInfo;

}

public String getUserId() {

return userId;

}

public String getPassWord() {

return passWord;

}

public boolean getSaveInfo() {

return saveInfo;

}

public ActionErrors validate(ActionMapping mapping,HttpServletRequest request)

{

ActionErrors ae = new ActionErrors();

if (userId == null || userId.equals(""))

{

ae.add("userId", new ActionError("error.no.userId"));

}

if (passWord == null || passWord.equals("")) {

ae.add("passWord", new ActionError("error.no.passWord"));

}

return ae;

}

}

--

Since I defined boolean saveInfo = true;

and saveInfo is the associated property, the box will be checked when the form is displayed.

Hope this helps.....[/nobr]

anurag_dasha at 2007-7-12 15:27:09 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...