Struts formbean question

I have a simple form, with a field, say, number, of type Integer, and a search button. when the user clicks on search, the request first goes to the formbean, to set the number, with method, setNumber. In the user input form, if the user did not specify the value for number, then, the formbean set it to be 0 automatically. How can I force it to be null when user doesnot enter any value for the number field.
thank you.

What are you trying to do? Are you using Integer or int? int variables can�t be null. Maybe you should try to use a String and then validate it using the validator.xml defined in struts for your form.

Similar Messages

  • BC4J + Struts: Design questions!

    OK, I'm wanting to use Struts with BC4J and have a design question for you BC4J users and gurus.
    Here's how I think things would work:
    1. User requests page
    2. Struts ActionServlet calls perform() on Struts ActionForm
    3. Struts ActionForm instantiates BC4J AppModule and calls business method
    4. BC4J AppModule instantiates necessary BC4J ViewObjects and performs business operations which return data
    5. Struts ActionForm receives value objects from BC4J AppModule
    6. Struts ActionForm populates Struts FormBean
    7. Struts ActionForm forwards to Struts JSP which displays Struts FormBean
    I prefixed the components with Struts/BC4J to keep things clear where things belong.
    Now, here are my questions:
    In step 3, what's the best method of doing this? Do I need to do JNDI lookups every time? What's the performance overhead of this? Anyone have any best-practice code that does this?
    Is this the accepted way of doing things? Is there a better way of designing this system?
    Thanks!

    In Step3 you should use the ApplicationModule pooling framework, especially if you are trying to work in stateful mode because the pooling automatically handle the AM activation/passivation.
    There are different way to go at it.
    If you are using the BC4J custom tag library and have an ApplicationModule tag in your jsp, the pooling is already initialize. By the time your action is trigger you just need to retrieve the am using the application id:
    in your jsp:
    <jbo:ApplicationModule id="myAM" ... />
    in your Action implementation:
    HttpContainer container = HttpContainer.getInstanceFromSession(request.getSession());
    SessionCookie cookie = container.getSessionCookie("myAM");
    ApplicationModule am = null;
    if (cookie != null)
    am cookie.useApplicationModule();
    This AM id can be passed as URL parameter...
    If you do have a JSP with an AM tag you need to create the pool with findSessionCookie call.
    For more info about AM pooling look at the end of this thread for Steve resources:
    http://forums.oracle.com/forums/message.jsp?id=912431&gid=513211
    This is what we are currently doing for to provide support for BC4J in Struts for our next release.
    Charles.

  • Struts Interview questions

    Send Struts interview question in my mail id [email protected]

    send me struts interview questionsDumb idiots. Couldn't you read the thread?another racist?!?Another idiot. Spamming fora again?!?Sorry Maris not here now please try again later.No thanks. I'm tired os talking nonsense. :(Sorry. :(
    You do know that despite any other commentary over time this thread will balloon to 100's of posts just like 2 and 4 though right?
    <crawling behind rock again/>

  • Struts ActionMapping Question

    Hello,
    I am pretty new to Struts and have hit a snag.
    I understand the concept of the ActionMapping like this: The Action Servlet reads the request and matches up the html form with the proper form bean (and forwards) and sends it all to the action class which does the pocessing and forwards on to the specified forward.
    My question is, how does this process change if I don't have an html form?
    I want to display editPerson.jsp with the information from Bob's account by clicking on a link like this:
    <a href="editPerson.jsp?personId=bob">Edit Bob</a>but editPerson.jsp is expecting to see a Person bean in session scope and it is not there. How do I pass personId to a formless ActionMapping so that I can get to my DisplayPerson class to instantiate the Person bean, store it in session and forward to editPerson.jsp?

    I think I have the same problem, but I'll go over it again to try to make sure.
    I have a table full of data; on each element of the table I want to put a link so the user can look at the details for that row.
    I know I can use to invoke an action, and likewise <html:link ... with a parameter, and that the parameter needs to translate to a string.
    I can use a string that server-end code can then use to retrieve a bean, and what I want is to have that bean be the formbean for the form that displays all the data for the row. In other words, I'm displaying some info about one item on the row, and I want to go to a page that displays a bean having all the data for that item.
    It seems to me what I want to do is invoke an action that has that bean in the "form-beans" mapping attached to the action, but I don't know how to do it. I can't set the bean in the JSP that displays the table; it doesn't know which row to use until the user clicks.
    It seems like I could have an action that takes the row identifier, creates the bean I want, and forwards to another action, but does that work? I thought an action was activated by the user clicking on a submit button -- is there a way to have an action execute the code I need and then forward to another action without requiring a user action in between?
    Or is there another way to go from a link in my table of summary data to a page with a bean containing all of the data?
    rc

  • Struts FormBean scope

    Do I need to put the form bean back in the request when in my Action class
    Following the process below:
    1. JSP page submits to Struts Action
    2. FormBean is populated and then validated ( configurable)
    3. FormBean is passed to Action class
    4. Business etc logic performed
    5. Forward to JSP performed
    What I am trying to ascertain is the following:
    From what I understand so far the FormBean will be available to my JSP ( from step 5 ) automatically - I don't have to put it back into the request. Now if I modify the form bean - maybe to update / set some new fields, do I have to re add the FormBean to the request or would I have modified the underlying bean via the existing reference form the action class?

    post your entry in the struts-config.xml. From what I gathered from your question your results page which you forward to :
    ex
    <forward name="success"
    path="/WEB-INF/results/confirmation.jsp"/>
    you do not have to re add the bean or anything. The bean will still be available to you. So reference the bean inside confirmation.jsp

  • Struts+Tiles question

    Hi all,
    I have a simple question trying to use struts 1.2
    I'm using Tiles and I have defined a layout that includes:
    header.jsp
    left-menu.jsp
    content
    rigth-menu.jsp
    footer.jsp
    "content" get updated with the current page asked by the user, but the web app supports multilanguage and right-menu.jsp has links to the supported lanuages.
    My question is, since by nature rigth-menu doesn't know what page is currently displayed, what is the best practice to let know rigth-menu.jsp with the Action mapping currently associated with the page currently displayed in order to display a link to the same page in other lamgages?
    Regards,
    OO

    You might want to try a struts forum.

  • Struts beginner question

    hi everyine
    i am new to struts.please tell me how to use struts.how i can use jsp and servlet page
    i am usinf sun applications server with netbeans ide .
    for usinf struts in netbeans what all i have to change
    thankyou

    Here you are having the answer for both the question.
    http://www.jajakarta.org/struts/struts1.2/documentation/ja/target/faqs/netbeans.html
    Go to the link and click Kiskstart at top left of the page to know about struts.The struts configuration is given for Eclipse and Netbeans IDE.

  • Struts collection question

    hi friends,
    I have question with struts collection. I have a colletion called chapters which contains about 10 items(strings) , i am displaying these items in jsp with iterate tag and displaying the collection items , one on each line..
    now i want to place a small symbol like arrow beside eash collection item in jsp page so that when i click the symbol it should reposition the items....like if i click the symbol beside item1, then item1 should move to item2 position and item2 should move to item1 position....
    Any ideas please
    Sorry please tell me if i am not clear
    Thanks in advance

    go tru below code to display alert messsaces to the user
    <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
    <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
    <html:html>
    <head>
    <title>
    getPID
    </title>
    <html:javascript formName="pidAForm"/>
    </head>
    <body bgcolor="#ffffff">
    <html:errors/>
    <html:form action="/pidAction" onsubmit="return validatePidAForm(this)">
    <table>
    <tr>
    <td><bean:message key="check.appid"/></td>
    <td><html:text property="applicationID"></html:text></td>
    <td><button id="btnApplication" value="choose"></button>
    </td>
    </tr>
    <tr>
    <td><bean:message key="check.projid"/></td>
    <td><html:text property="projectID"></html:text></td>
    <td><button id="btnProject" ></button>
    </td>
    </tr>
    <tr>
    <td><bean:message key="check.objid"/></td>
    <td><html:text property="objectID"></html:text></td>
    <td><button id="btnObject" ></button>
    </td>
    </tr>
    <tr>
    <td><bean:message key="check.date"/></td>
    <td><html:text property="date"></html:text></td>
    <td><button id="btnDate" ></button>
    </td>
    </tr>
    <tr>
    <td><html:submit value="submit"/></td>
    </tr>
    </table>
    </html:form>
    </body>
    </html:html>

  • Struts workflow question

    In "Struts in Action" on page 228 paragraph Chaining Actions, author says in regard to exchanging the same form bean between two actions:
    "...create a new form bean (in the first action) for the second action, populate it, and add it to the request. If both actions use the same bean type, and you need them both, you can add an "attribute" property to one of the Action's mappings so that it is stored under a different attribute name":
    <action
            path="/item/Edit"
            type="org.apache.gavel.http.ModelHelper"
            name="itemForm"
           attribute="itemFormAdd"
           scope="request"
           validate="false"
          parameter="org.apache.gavel.item.Select">
          <forward
                         name="continue"
                         path="/pages/item/Form.jsp"/>
    </action>Could somebody pls clarify this and provide a full example for two actions and two form beans where one form bean is common to both actions, e.g. in workflow:
    jsp1..............formbean1
    Action1.........formbean1
    jsp2..............formbean2, formbean1
    Action2.........formbean2, formbean1
    i.e. Action2 must have both form beans available to complete its task. Which form bean should go to "attribute" property, formbean1 or formbean2?
    If form beans formbean1 and formbean2 are DynaValidatorForm kind of beans, is that possible at all? Or we need to use ActionForm beans for this?
    Thanks,

    Anybody?

  • Struts tag question

    I am writing a web app that uses Struts and the associated tag libs in the JSP. I am trying to create a form with three text fields, each of which will be initialized to a value from a bean referenced in the top of the JSP. When I try the following, I get an exception saying the value must be followed by a ". How can I do this?
    <html:form action="screens/UpdateName.do">
    <table>
    <tr><td> First: </td>
    <td> <html:text property="firstName" size="22" maxlength="22" value=<%= Customer.getFirstName();%>/>
    </td>
    </tr>
    <tr><td> Middle: </td>
    <td> <html:text property="middleName" size="22" maxlength="22"/>
    </td>
    </tr>
    <tr><td> Last: </td>
    <td> <html:text property="lastName" size="22" maxlength="22"/>
    </td>
    </tr>
         <tr><td colspan="2">
    <html:submit property="submit" value="Enter"/>
    </input>
    </td>
         </tr>
    </table>
    </html:form>
    Customer is the name of the bean with the name data in it.

    You don't need the value attribute for this tag. The property attribute will ensure that the text field gets the value from the Customer bean firstName property.
    You would use the value attribute if you weren't specifiying a property.
    Dave

  • Basic struts config question

    Hi,
    What does the "input" attribute of the struts-config.xml do?
    Thanks

    Check out the [url http://struts.apache.org/dtds/struts-config_1_2.dtd]struts-config dtd[ur;]. It documents each of the attributes/tags you can use in the xml file.
         input           Module-relative path of the action or other resource to
                         which control should be returned if a validation error is
                         encountered. Valid only when "name" is specified. Required
                         if "name" is specified and the input bean returns
                         validation errors. Optional if "name" is specified and the
                         input bean does not return validation errors.Simply put, it specifes the jsp page to return control to when validation fails - ie return you to the input screen, display errors and let you correct them.
    Cheers,
    evnafets

  • Struts app question

    Hi everybody.
    I'm still working on my first struts app.
    I have a form with one row(consists of 3 text tags and 1 select tag, where I can choose a currency code) and one submit button.
    How can I do this......I want to have here another button and on its click I want to add another same row that consists of same elements.
    And than I want to have the SAVE button, that will save the data from those few rows into the database.
    It is possible to do it and how?
    Thanks a lot.
    my jsp:
    <%@ page.....
    <%@ taglib.....
    <jsp:useBean id="helper" class="helper.Helper" scope="session" />
    <jsp:useBean id="zalohy" class="model.PdZalohyCppTabLocalDTO" scope="session" />
    <html>
    <head>
    <link href="<html:rewrite page="/rr.css" />" rel="stylesheet" type="text/css">
    <title><bean:message key="title.cpp.cppform"/></title>
    <script type="text/JavaScript"></script>
    </head>
    <body>
    <form>
    <h1>CPP</h1>
    <logic:messagesPresent>
    <span id="errorsHeader"><bean:message key="errors.validation.header"/></span>
    <html:messages id="error">
    <li><c:out value="${error}"/></li>
    </html:messages>
    <hr>
    </logic:messagesPresent>
    <html:form action="insertCpp">
    <table>
    <tr>
    <td>Money:</td>
    <td>Currency:</td>
    <td>Name:</td>
    <td>Plan:</td>
    </tr>
    <tr>
    <td><html:text property="money"/></td>
    <td>
    <html:select name="cppForm" property="codCur">
    <html:options collection="MenaBean" property="codCur" labelProperty="nameCur"/>
    </html:select>
    </td>
    <td><html:text property="name"/></td>
    <td><html:text property="plan"/></td>
    </tr>
    </table>
    <html:submit><bean:message key="button.cpp.submit"/></html:submit>
    </html:form>
    </form>
    </body>
    </html>

    nobody? ...pls,look at it

  • Help me for a basic Struts tag question.

    I need display a image on my page, but I don't know how to replace
    "?" in <html:img src="?" /> with one of my bean's property.
    My teacher asked us must not use any <%..%> style expressions
    Please help me do it.
    Thanks

    ok - too early - what I mean to say is, scratch the bean:write, I didn't read very clearly, use your html:img but use the property attribute, not the src attribute.
    Sorry for the confusion
    Lee

  • Strut Question

    I have a question about struts. I know Strut is good framework for designing a large website. It has a lot of classes that help to design well scaled websites. What about performance? Does it slow the processing of request. if speed is the main issue is it good idea to use strut?if website needs to handle about 200,000
    request per hour would you advice to use strut?

    You may get more responses in this forum but I thought I'd pass along a struts specific resource that you could also try.
    A good source of help on Struts specific questions is the Struts user mailing list at Apache ... it's filled with helpful people, and the archives are a gold mine of good advice. To subscribe, send an empty message to <[email protected]>.

  • EJB 3.0 and Struts 1.0

    Have a Struts/EJB question...
    If I have a web-form backed by an ActionForm in Struts, where the user
    types in a record that maps directly to an EJB3 entity class and a
    corresponding db-table, is it advisable (or even possible) to somehow
    use the same class for the ActionForm and the EJB?
    Im thinking the 2 beans, they have basically the same setter/getter
    methods,
    but the form-bean extends ActionForm, while the Entity class
    implements serializable...
    Is it possible to use one and the same class for both purposes... or
    maybe one extends the other...
    Or should they just be two different classes, and have to copy data
    back and forth between them?
    What is "best practice" here?
    Edited by: vb.bajpai on Feb 13, 2009 4:13 AM

    Well, the "best practice" is the one that better fits for you. Your idea of making another bean for struts, has been thought before. That technique is called "DTO Pattern". Search the java blueprints for the DTO Pattern.
    So you have 2 options
    Use EJB entities through all your app
    pros: less code to write
    cons: highly coupled code. struts must stick to your EJB entity beans.
    Use the DTO pattern
    pros: loose coupled design. you can change your entities and your struts forms wont be affected.
    cons: more code to write. You may need help from a bean to bean mapper like dozer or ezconvert
    PS: DTO (Data Transfer Object), VO (Value Object), and TO (Transfer Object) are all synonyms.

Maybe you are looking for

  • Overriding attributes in ABAP objects

    Hello, I currently want know if it is possible to override attributes in ABAP objects. i know it is possible with methods. I have extend a previous class functionality and want to change the refrence type of an attribute from the parent class, but on

  • Installing Bootcamp Drivers on Macbook Air?

    When I installed Bootcamp this morning after the seventieth problem had been solved, I finally hit ANOTHER roadblock. Since the MacBook Air doesn't have a DVD drive, I need to use my Superdrive to insert discs and stuff. Now, all my drivers that I ne

  • Aging email

    My BB drops emails after they get to be older than 30 days. I have the retention option set at forever. Have even tried the 180 days option. How do I get the emails to stay past 30 days.

  • Problem with TouchSmart tx2-1275dx Starting. Help!

    Hello all, I am having a huge problem with my pc! In the last week, I have had to do 2 system recoveries on my computer after I receive a message at startup that says that my pc has failed to start windows, which may be due to the last shut down or a

  • Audition does not play nor record

    Auditon CS6 does not play nor record. I can click into the file but when I press play or space there is no reaction. "no transport". I have uninstalled and reinstalled the program. No luck. Earlier the onboard processor hat to be replaced (hp warrant