You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by George Christman <gc...@cardaddy.com> on 2011/07/05 20:02:22 UTC

T5 Selected Attribute

Hello, In my onPrepare method, I'm trying to select a select menu option by
default. I'm aware of tapestry being able to handle this automatically by
setting the object value, however I haven't had any success. If someone
could point me in the right direction, I'd greatly appreciate it.

--
View this message in context: http://tapestry.1045711.n5.nabble.com/T5-Selected-Attribute-tp4554181p4554181.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5 Selected Attribute

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Tue, 05 Jul 2011 16:04:59 -0300, George Christman  
<gc...@cardaddy.com> wrote:

> Object entity label using UUID transient temp Ids. I'm also using an  
> encoder with the select menu. Not sure if that matters.

They don't. Funding class sources, specially hashCode() and equals(), do  
matter. ;)

-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5 Selected Attribute

Posted by George Christman <gc...@cardaddy.com>.
Object entity label using UUID transient temp Ids. I'm also using an encoder
with the select menu. Not sure if that matters. 

fundingModel = selectModelFactory.create(purchaseRequest.getFundings(),
"label");

Thanks for the article, reading as we speak. 

--
View this message in context: http://tapestry.1045711.n5.nabble.com/T5-Selected-Attribute-tp4554181p4554342.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5 Selected Attribute

Posted by Lenny Primak <lp...@hope.nyc.ny.us>.
I don't even use @Property annotation, is's just @Getter / @Setter from Lombok,
also SneakyThrows is great.  Cuts down on code tremendously.  

On Jul 6, 2011, at 1:33 PM, George Christman wrote:

> Thanks Thiago, I finally have this some what working :) Add some logic so
> it's not resetting every menu on the page and we should be good to go lol. 
> 
> Any thoughts on using Lombok's annotations for the entity classes? First
> I've heard of it.
> 
> --
> View this message in context: http://tapestry.1045711.n5.nabble.com/T5-Selected-Attribute-tp4554181p4557483.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5 Selected Attribute

Posted by George Christman <gc...@cardaddy.com>.
Thanks Thiago, I finally have this some what working :) Add some logic so
it's not resetting every menu on the page and we should be good to go lol. 

Any thoughts on using Lombok's annotations for the entity classes? First
I've heard of it.

--
View this message in context: http://tapestry.1045711.n5.nabble.com/T5-Selected-Attribute-tp4554181p4557483.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5 Selected Attribute

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Wed, 06 Jul 2011 14:06:26 -0300, George Christman  
<gc...@cardaddy.com> wrote:

> So would I be generating the hashCode equals within the funding class?

Yes. The class whose instances are used as options in the Select component.

> Also, that select menu is being used within an AjaxFormLoop with a value  
> encoder which is using the Transient temp id. How would hashCode work  
> when the ID is null?

Return some fixed negative number.

-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5 Selected Attribute

Posted by George Christman <gc...@cardaddy.com>.
So would I be generating the hashCode equals within the funding class? Also,
that select menu is being used within an AjaxFormLoop with a value encoder
which is using the Transient temp id. How would hashCode work when the ID is
null?

Thanks Thiago

--
View this message in context: http://tapestry.1045711.n5.nabble.com/T5-Selected-Attribute-tp4554181p4557419.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5 Selected Attribute

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
If you use Eclipse, Source -> Generate hashCode() and equals() generates  
good implementations of these methods. You'll need to choose the fields  
used: check just the id one.

On Wed, 06 Jul 2011 12:23:34 -0300, George Christman  
<gc...@cardaddy.com> wrote:

> Here's my Funding class
>
> @Entity
> public class Funding extends BaseEntity implements Labeled {
>
> //BaseEntity is just the generated ID.
>
>     private String name;
>
>     private String label;
>
>     @OneToMany(mappedBy = "funding", cascade=CascadeType.ALL)
>     private List<LineItemFunding> lineItemFundings;
>
>     @ManyToOne
>     @JoinColumn(name = "ifas_object_code_id", nullable = true)
>     private IfasObjectCode ifasObjectCode;
>
>     @ManyToOne
>     @JoinColumn(name = "pr_id", nullable = false)
>     private PurchaseRequest purchaseRequest;
>
>     @Transient
>     private long tempId;
>
>     public Funding() {
>         tempId = UUID.randomUUID().getLeastSignificantBits();
>     }
>
>     public long getTempId() {
>         return tempId;
>     }
>
>     public void setTempId(long tempId) {
>         this.tempId = tempId;
>     }
>
>     public PurchaseRequest getPurchaseRequest() {
>         return purchaseRequest;
>     }
>
>     public void setPurchaseRequest(PurchaseRequest purchaseRequest) {
>         this.purchaseRequest = purchaseRequest;
>     }
>
>     public IfasObjectCode getIfasObjectCode() {
>         return ifasObjectCode;
>     }
>
>     public void setIfasObjectCode(IfasObjectCode ifasObjectCode) {
>         this.ifasObjectCode = ifasObjectCode;
>     }
>
>     public List<LineItemFunding> getLineItemFundings() {
>         return lineItemFundings;
>     }
>
>     public void setLineItemFundings(List<LineItemFunding>  
> lineItemFundings)
> {
>         this.lineItemFundings = lineItemFundings;
>     }
>
>     public String getName() {
>         return name;
>     }
>
>     public void setName(String name) {
>         this.name = name;
>     }
>
>     public String getLabel() {
>         return _name + " - " + _ifasObjectCode;
>     }
>
>
>
> --
> View this message in context:  
> http://tapestry.1045711.n5.nabble.com/T5-Selected-Attribute-tp4554181p4557089.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>


-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
Consultor, desenvolvedor e instrutor em Java, Tapestry e Hibernate
http://www.arsmachina.com.br

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5 Selected Attribute

Posted by George Christman <gc...@cardaddy.com>.
Here's my Funding class

@Entity
public class Funding extends BaseEntity implements Labeled {

//BaseEntity is just the generated ID. 

    private String name;

    private String label;

    @OneToMany(mappedBy = "funding", cascade=CascadeType.ALL)
    private List<LineItemFunding> lineItemFundings;

    @ManyToOne
    @JoinColumn(name = "ifas_object_code_id", nullable = true)
    private IfasObjectCode ifasObjectCode;

    @ManyToOne
    @JoinColumn(name = "pr_id", nullable = false)
    private PurchaseRequest purchaseRequest;

    @Transient
    private long tempId;

    public Funding() {
        tempId = UUID.randomUUID().getLeastSignificantBits();
    }

    public long getTempId() {
        return tempId;
    }

    public void setTempId(long tempId) {
        this.tempId = tempId;
    }

    public PurchaseRequest getPurchaseRequest() {
        return purchaseRequest;
    }

    public void setPurchaseRequest(PurchaseRequest purchaseRequest) {
        this.purchaseRequest = purchaseRequest;
    }

    public IfasObjectCode getIfasObjectCode() {
        return ifasObjectCode;
    }

    public void setIfasObjectCode(IfasObjectCode ifasObjectCode) {
        this.ifasObjectCode = ifasObjectCode;
    }

    public List<LineItemFunding> getLineItemFundings() {
        return lineItemFundings;
    }

    public void setLineItemFundings(List<LineItemFunding> lineItemFundings)
{
        this.lineItemFundings = lineItemFundings;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getLabel() {
        return _name + " - " + _ifasObjectCode;
    }



--
View this message in context: http://tapestry.1045711.n5.nabble.com/T5-Selected-Attribute-tp4554181p4557089.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5 Selected Attribute

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Wed, 06 Jul 2011 11:35:23 -0300, George Christman  
<gc...@cardaddy.com> wrote:

> Is there any chance you guys could help me write out the hashCode equals  
> with the select menu.

Yes, but you haven't sent us what we need to help you: the Funding class  
source.

-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5 Selected Attribute

Posted by Lenny Primak <lp...@hope.nyc.ny.us>.
I suggest you take a look at project Lombok. 
It has annotation @Data that automatically generates all getters, setters, toStong
and hashCode automatically and at runtime for you. Perfect for entity classes and makes code very very small. 



On Jul 6, 2011, at 10:35 AM, George Christman <gc...@cardaddy.com> wrote:

> Is there any chance you guys could help me write out the hashCode equals with
> the select menu. I'm having a difficult time comprehending this for some
> reason. I'm hoping after seeing an example, I'll be able to finally bring it
> all together. 
> 
> To keep things simple, the tml contains a nested loop containing a select
> menu. 
> 
> .tml
> <t:Loop source="purchaseRequest.lineItems" value="lineItem">
>     <t:Loop source="lineItem.lineItemFundings" value="lineItemFunding">
>               <t:Select value="lineItemFunding.funding"
> model="fundingModel"/>t
>    </t:Loop>
> </t:Loop>
> 
> java code
> 
> @Property
> private PurchaseRequest purchaseRequest;
> 
> @Property
> private LineItem lineItem;
> 
> @Property
> private LineItemFunding lineItemFunding;
> 
> @Property
> @Persist
> private SelectModel fundingModel;
> 
> void onPrepareForRender() {
>     fundingModel = selectModelFactory.create(purchaseRequest.getFundings(),
> "label");
> 
>    //for testing, i'm manually setting the value to get it to reload the
> menu with selected attribute.
> 
>    for(LineItem _lineItem : purchaseRequest.getLineItems()) {
>         for (LineItemFunding _lineItemFunding :
> _lineItem.getLineItemFundings()) {
>             //This is where I'm attempting to set the _lineItemFunding menu
> with funding object.
>              _lineItemFunding.setFunding((Funding)
> session.get(Funding.class, 1));
>         }
>    }
> }
> 
> When the form is submitted, I'm only persisting the data to the user session
> and not committing to database. I'm only doing this to reload all the select
> menus without losing any other form data. I'm just not sure how to write the
> hashCode to work with this.
> 
> Thanks everyone, you've been a tremendous help. 
> 
> 
> --
> View this message in context: http://tapestry.1045711.n5.nabble.com/T5-Selected-Attribute-tp4554181p4556947.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5 Selected Attribute

Posted by George Christman <gc...@cardaddy.com>.
Is there any chance you guys could help me write out the hashCode equals with
the select menu. I'm having a difficult time comprehending this for some
reason. I'm hoping after seeing an example, I'll be able to finally bring it
all together. 

To keep things simple, the tml contains a nested loop containing a select
menu. 

.tml
<t:Loop source="purchaseRequest.lineItems" value="lineItem">
     <t:Loop source="lineItem.lineItemFundings" value="lineItemFunding">
               <t:Select value="lineItemFunding.funding"
model="fundingModel"/>
    </t:Loop>
</t:Loop>

java code

@Property
private PurchaseRequest purchaseRequest;

@Property
private LineItem lineItem;

@Property
private LineItemFunding lineItemFunding;

@Property
@Persist
private SelectModel fundingModel;

void onPrepareForRender() {
     fundingModel = selectModelFactory.create(purchaseRequest.getFundings(),
"label");

    //for testing, i'm manually setting the value to get it to reload the
menu with selected attribute.
    
    for(LineItem _lineItem : purchaseRequest.getLineItems()) {
         for (LineItemFunding _lineItemFunding :
_lineItem.getLineItemFundings()) {
             //This is where I'm attempting to set the _lineItemFunding menu
with funding object.
              _lineItemFunding.setFunding((Funding)
session.get(Funding.class, 1));
         }
    }
}

When the form is submitted, I'm only persisting the data to the user session
and not committing to database. I'm only doing this to reload all the select
menus without losing any other form data. I'm just not sure how to write the
hashCode to work with this.

Thanks everyone, you've been a tremendous help. 
  

--
View this message in context: http://tapestry.1045711.n5.nabble.com/T5-Selected-Attribute-tp4554181p4556947.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5 Selected Attribute

Posted by Taha Hafeez <ta...@gmail.com>.
http://www.jchq.net/certkey/0902certkey.htm


What is the type of value bound to select ?

regards
Taha


On Wed, Jul 6, 2011 at 12:17 AM, George Christman
<gc...@cardaddy.com>wrote:

> Thanks everyone, I'm pretty new to backend development, so I guess I don't
> completely understand hashcode equals and how it works.
>
> --
> View this message in context:
> http://tapestry.1045711.n5.nabble.com/T5-Selected-Attribute-tp4554181p4554302.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: T5 Selected Attribute

Posted by George Christman <gc...@cardaddy.com>.
Thanks everyone, I'm pretty new to backend development, so I guess I don't
completely understand hashcode equals and how it works. 

--
View this message in context: http://tapestry.1045711.n5.nabble.com/T5-Selected-Attribute-tp4554181p4554302.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5 Selected Attribute

Posted by Taha Hafeez <ta...@gmail.com>.
Hi

Firstly if you set a default value in onPrepare(), it will not only set the
value during render but also during submission, which I don't think you
intend to. A better choice will be onPrepareForRender().

Secondly, all you have to do is set the value that is bound to the select
component to a value you want to have by default. Also, as Thiago has
already pointed out, the value's class must implement equals() and
hashCode().

Sorry, but I could not understand your code in context of the problem

regards
Taha


On Tue, Jul 5, 2011 at 11:47 PM, George Christman
<gc...@cardaddy.com>wrote:

> Hi Taha,
>
> this is my test code.
>
>        Long key = new Long("-8879035676972742623");
>
>        for(LineItem _lineItem : getPurchaseRequest().getLineItems()) {
>            for (LineItemFunding _lineItemFunding :
> _lineItem.getLineItemFundings()) {
>                if(_lineItemFunding.getTempId() == key) {
>                    _lineItemFunding.setFunding((Funding)
> session.get(Funding.class, 6));
>                }
>
>            }
>        }
>
>
>
> --
> View this message in context:
> http://tapestry.1045711.n5.nabble.com/T5-Selected-Attribute-tp4554181p4554217.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: T5 Selected Attribute

Posted by George Christman <gc...@cardaddy.com>.
Hi Taha, 

this is my test code. 

        Long key = new Long("-8879035676972742623");
        
        for(LineItem _lineItem : getPurchaseRequest().getLineItems()) {
            for (LineItemFunding _lineItemFunding :
_lineItem.getLineItemFundings()) {
                if(_lineItemFunding.getTempId() == key) {
                    _lineItemFunding.setFunding((Funding)
session.get(Funding.class, 6));
                }

            }
        }



--
View this message in context: http://tapestry.1045711.n5.nabble.com/T5-Selected-Attribute-tp4554181p4554217.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5 Selected Attribute

Posted by Taha Hafeez <ta...@gmail.com>.
Hi

Can you share the code ?

regards
Taha


On Tue, Jul 5, 2011 at 11:32 PM, George Christman
<gc...@cardaddy.com>wrote:

> Hello, In my onPrepare method, I'm trying to select a select menu option by
> default. I'm aware of tapestry being able to handle this automatically by
> setting the object value, however I haven't had any success. If someone
> could point me in the right direction, I'd greatly appreciate it.
>
> --
> View this message in context:
> http://tapestry.1045711.n5.nabble.com/T5-Selected-Attribute-tp4554181p4554181.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: T5 Selected Attribute

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Tue, 05 Jul 2011 15:02:22 -0300, George Christman  
<gc...@cardaddy.com> wrote:

> Hello,

Hi!

> In my onPrepare method, I'm trying to select a select menu option by  
> default. I'm aware of tapestry being able to handle this automatically by
> setting the object value, however I haven't had any success. If someone
> could point me in the right direction, I'd greatly appreciate it.

The class of the select options needs to have good hashCode() and equals()  
implementations (as almost any other entity class, by the way).

-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org