You need to sign in to do that
Don't have an account?
I want some easy solution for my hard codes on the Visual page and the Controller class
<apex:page controller="productslistpage" showHeader="false"> <Apex:form > <apex:outputText value="{!usermode} {!Name}" style="float:right;font-weight:bold;color:black;font-size:16px;text-align:left;" /> <br/><p style="font-size:19px;font-weight:bold;"> Products available today </p><br/> <apex:CommandLink action="{!prod1button}" ><br/> <apex:image url="{!$Resource.Testprod1}" width="100" height="180"/><br/> <h3>Logo Shirt (Gray)</h3> </apex:commandlink> <p>$20.00</p> </apex:form> </apex:page>
Controller
public Class productslistpage{ public list<inventory__c> prodlist{get; set;} public string PID{get; set;} public string name{get; set;} public string usermode{get; set;} public productslistpage(){ this.name = ApexPages.currentPage().getParameters().get('Name'); this.usermode = ApexPages.currentPage().getParameters().get('usermode'); prodlist = [Select ButtonName__c,Name, Price__c, Stocks__c,productid__c from Inventory__c]; } PageReference pg = new PageReference('/apex/testprodpage'); public pagereference prod1button(){ PID = '10004'; pg.getParameters().put('PID', PID); return pg; } }
The Vf page contains commandbutton for productone as well as name and other details of product, button is linked to pagereference prod1button which passes the product id to the other page.
What I need help with is I don't want to write each block of code similar to one eanother in the VF and the controller class.Is there a way I can generalise the code with anything, because i don't know how I can,I thought of Repeat but i don't think it helps with the methods in the class, as each method will be required , If i am not wrong. Please any help is appreciated.
Thank you,
Niknit
use in tsetprod vf page
but How do I display the commandbutton for each product
as you see the product name and image is a commandbutton, clicking it leads to another page, with your code how do i place the commandbutton?
I am sorry i am confused
productslistpage vf page
I have updated
Thanks Varun,
But the thing is , I went with this before, i even went with repeat, the problem is how do I change the image and the methodname() [for pagereference], because right now it all leads to same product page and displays same pic for all products, I tried adding a column in the table for the method name and pic name, but when i try to add in the vf page between {! } it gives an error, eg - object name- inventory, column name for method name - Prodbutton , Now if i try to call it , <apex:CommandLink action="{!a.prodbutton}" ><br/> , this gives an error as it searches for variable name "a.prodbutton" as in whole instead of querying inventory__c.prodbutton.
use repeat
i will do someting like that
you have to upload images in documnets
you have custome field button name put the url of image in buttonname fild
these are images we store in document
and we can put the in button name filed or (in any other filed you can also hide it from layout)
then save path of image in text type fild
apex code
Page
output
when you click on image button pass id of production to controller and get detail of same product you clicked in neext page.
I Hope this is helpful and best answer from my side.