What will be approach in Composite C1 for Creating Custom Form? - c1-cms

I wanted to create a page like following image in Composite-C1 with File upload functionality. But I am stucked here unable to find any thing on google. What will be the best approach to do this. How to create a simple razor functions to do this. What will be in form actions.

I would go ahead and use the free and very flexible Contrib FormBuilder which you can get from here https://bitbucket.org/burningice/compositec1contrib.formbuilder. Under 'Downloads' is the zip-files, which you would go ahead and download and install as Local Packages from within the C1 Console.
For this example you would need CompositeC1Contrib.FormBuilder.0.8.7 and CompositeC1Contrib.FormBuilder.POCO, and if you don't already use the Contrib.Core package, you need grab that one from here https://bitbucket.org/burningice/compositec1contrib/downloads. Install them in this order
Core
FormBuilder
FormBuilder.POCO
When that is all done, you need to create two thing, the form definition and a razor file to present the form
The form defintion is a .cs class file, kinda like a Model in NVC, with a number of properties and a submit handler
Form.cs
using System;
using CompositeC1Contrib.FormBuilder;
using CompositeC1Contrib.FormBuilder.Attributes;
using CompositeC1Contrib.FormBuilder.Validation;
using CompositeC1Contrib.FormBuilder.Web.UI;
namespace StackExchange
{
[FormName("Forms", "Feedback")]
public class Form : IPOCOForm
{
[FieldLabel("Feedback type")]
[RequiredField("Required")]
[DropdownInputElement]
public string FeedbackType { get; set; }
[FieldLabel("Version")]
[RequiredField("Required")]
[DropdownInputElement]
public string Version { get; set; }
[FieldLabel("Attachment")]
[RequiredField("Required")]
public FormField File { get; set; }
[FieldLabel("Version")]
[RequiredField("Required")]
[TextAreaInputElement]
public string Description { get; set; }
public void Submit()
{
throw new NotImplementedException();
}
}
}
The razor file is what controls the layout of the form. Out of the box it has helper methods to just dump all your fields downwards, you're free to add any html, markup and styling in it as you want.
Go ahead and create a .cshtml file named Feedback.cshtml and put in in your ~/App_Data/Razor/Forms folder
#inherits POCOBasedFormsPage<Feedback>
#if (IsSuccess && (SuccessResponse != null && !SuccessResponse.IsEmpty))
{
#EvaluateMarkup(SuccessResponse.Root)
}
else
{
#EvaluateMarkup(IntroText.Root)
using (BeginForm(new { #class = "form-horizontal" }))
{
#WriteErrors()
#WriteAllFields()
#WriteCaptcha()
<div class="control-group submit-buttons">
<div class="controls">
<input type="submit" name="SubmitForm" class="btn btn-primary" value="Send Enquiry" />
</div>
</div>
}
}
Now you're ready to insert the form on a page on in a template as you'd like. It will turn up as a function named Forms.Feedback and is used like any other C1 Function as you're used to.

Related

.NET Tag Helper to replicate #Html.DisplayFor

I'm discovering .Net Core Tag Helpers and I was just curious to know if there are any tag helpers that replicate the #Html.DisplayFor. I think that the label tag helper replicates #Html.DisplayNameFor since it shows the property name on a model passed to the page, but is there an equivalent for #Html.DisplayFor for displaying a property value?
I'm assuming there isn't because in the microsoft .net core tutorials, razor pages that need to display the property value rather than the property name use the HTML helpers.
First, the tag helper is actually the "label asp-for". You can create a new tag helper that is a "label asp-text" helper.
Another option is to use another tag such as span and create a custom "span asp-for" tag helper.
Here is a simple span implementation:
[HtmlTargetElement("span", Attributes = FOR_ATTRIBUTE_NAME, TagStructure = TagStructure.NormalOrSelfClosing)]
public class CustomSpanTagHelper : InputTagHelper
{
private const string FOR_ATTRIBUTE_NAME = "asp-for";
public CustomSpanTagHelper(IHtmlGenerator generator) : base(generator)
{
}
public override void Process(TagHelperContext context, TagHelperOutput output)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
if (output == null)
{
throw new ArgumentNullException(nameof(output));
}
var metadata = base.For.Metadata;
if (metadata == null)
{
throw new InvalidOperationException(string.Format("No provided metadata " + FOR_ATTRIBUTE_NAME));
}
if (!string.IsNullOrWhiteSpace(metadata.Description))
{
output.Content.Append(metadata.Description);
}
if (metadata.IsEnum)
{
var description = (this.For.Model as Enum).GetDescription();
output.Content.Append(description);
}
base.Process(context, output);
}
}
You will need to register your custom tag helper in your _ViewImports.cshtml like this: (don't forget to rebuild)
#namespace MyProject.Web.Pages
#addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
#addTagHelper MyProject.Web.TagHelpers.CustomSpanTagHelper, MyProject.Web <-- custom import

Localizing buttons of a FacesContext.addMessage in adf

Hi i want to localize the buttons eg: OK, Cancel in ADF,
I am using the following code
FacesContext fctx = FacesContext.getCurrentInstance();
fctx.addMessage(VALIDATIONERROR,new FacesMessage(FacesMessage.SEVERITY_ERROR, errorMessage, errorMessage));
fctx.renderResponse();
I get the pop and the error message is localized, My question is how to localize the buttons which are on the pop up, ex: OK,CANCEL
I suppose you are talking about a af:dialog component. In that case i can think about two ways of doing so:
The af:dialog component has two properties: cancelTextAndAccessKey and affermativeTextAndAccessKey. They can take an EL which can take the key of a specific record into a .properties file (which is loaded as a resource bundle into the project. An example: cancelTextAndAccessKey="#{lang['popUp.dialog.button.cancel']}" (where lang is the name of the declared bundle in my case)
You can override the default component label, by creating a ListResourceBundle (which should be also loaded as a resource bundle into faces-config.xml, Application tab).
The code should be something like:
public class CTSResourceBundle extends ListResourceBundle {
public CTSResourceBundle() {
super();
}
#Override
protected Object[][] getContents() {
return new Object[][] {
{ "af_dialog.LABEL_YES", "Po" },
{ "af_dialog.LABEL_NO", "Jo" },
{ "af_dialog.LABEL_OK", "Ok" },
{ "af_dialog.LABEL_CANCEL", "Anullo" }
};
}
}

Create UI components on page load

I am currently working on oracle adf task flows and regions and I want to create and update some UI components on page load and for this I am using method call activity as default.The problem is that I am getting null values following is my code in the bean that executes on the method call.
package view;
import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;
import oracle.adf.view.rich.component.rich.output.RichOutputText;
public class testBean {
public testBean() {
}
public String testMethod() {
// Add event code here...
FacesContext facesContext = FacesContext.getCurrentInstance();
UIViewRoot root = facesContext.getViewRoot();
RichOutputText text = ( RichOutputText )root.findComponent( "r1:ot1" );
text.setValue( "Adding text on run time" );
return "product";
}
}
The set value method returning me null may be it is because the fragment product.jsff which is the view activity is not initiated and the output text with ot1 returning null.
The better approach to achieve the setting of value is to have a property in your bean say: textValue and then bind the value attribute of your ot1 with the property of the bean.
class TestBean{
private String textValue;
public String testMethod() {
textValue = "Adding text on run time";
}
public String getTextValue(){
return textValue;
}
}
Your JSPX would be:
<af:outputText id="ot1" value=#{beanName.textValue}" />

Adding External XML to a VisualForce DataTable/List

I am making an external call to a Server and returning XML (HTTPResponse). I then use a DOM parser to get a list of items.
How can I add the list of items to a DataTable/DataList?
How can I parse the XML structure into a Salesforce structure within the class itself?
Thank you
Hi eyesscream. All is working fine, except one thing. I needed to get deep in XML
Dom.XMLNode rootElement = doc.getRootElement();
for (Dom.XmlNode assets : rootElement.getChildElements()) {
if (assets.getName().trim() == 'models') {
for (Dom.XmlNode asset : assets.getChildElements()) {
if (asset.getName().trim() == 'model') {
for (Dom.XmlNode serial : asset.getChildElements()) {
if (serial.getName().trim() == 'modelNumber') {
text = serial.getText().trim();
allOptons.add(new SelectOption(text, text));
}
}
}
}
}
}
on VF page it duplicates the results. Why?
Go through your XML adding elements to a list of strings of wrapper objects if you need to store more than 1 parameter. Then such list can be assigned to dataTable, pageBlockTable, repeat etc tags without any problems. It's not like these tags work only on standard sObjects.
For a simple list of Strings with checkboxes you don't even need any helper classes.
public class StackXml{
public List<SelectOption> allOptions {get;private set;} // this will hold serial numbers for use in VF page.
// if you wouldn't plan to use VF with checkboxes, simple List<String> would be enough
public List<String> selectedOptions {get;set;}
public StackXml(){
allOptions = new List<SelectOption>();
selectedOptions = new List<String>();
String xmlString = '<serials><serialNumber>ver123</serialNumber><serialNumber>ver456 </serialNumber>' +
'<intrusion>something to prove it will be skipped</intrusion>' +
'<serialNumber>abc007</serialNumber></serials>';
Dom.Document doc = new Dom.Document();
doc.load(xmlString);
Dom.XMLNode rootElement = doc.getRootElement();
for(Dom.XmlNode node : rootElement.getChildElements()){
if(node.getName().trim() == 'serialNumber') {
String text = node.getText().trim();
allOptions.add(new SelectOption(text, text));
}
}
}
public void assign(){}
}
<apex:page controller="StackXml">
<apex:form>
<apex:selectCheckboxes value="{!selectedOptions}" layout="pageDirection">
<apex:selectOptions value="{!allOptions}"/>
</apex:selectCheckboxes>
<apex:commandButton value="Assign" action="{!assign}"/>
</apex:form>
<hr/>
<p>You have selected:</p>
<apex:dataList value="{!selectedOptions}" var="o">{!o}</apex:dataList>
</apex:page>

How to bind form to model in NancyFX

I'm new to NancyFX and trying to simply bind a posted form to my model.
In the module when trying to access the posted values I run following statement:
string email = this.Context.Request.Form["Email"];
Debug.WriteLine(email);
Result is:
"Nancy.DynamicDictionaryValue" instead of posted value
Can anybody tell me what newbie mistake I'm doing:
The form looks like:
<form method="post" action="account">
<input type="text" id="Email" />
<input type="password" id="Password" />
<input type="submit" value="Create" />
</form>
the routing in Module contructor:
Post["/"] = parameters => CreateAccount(parameters);
The dynamic dictionary returns a dynamic value, if you cast it to a string (implicitly or explicitly) you'll get what you want, or just use the build in model binder https://github.com/NancyFx/Nancy/wiki/Model-binding
Just adding to the correct answer above in the hope it is useful to nancy-newbies like me.
Because the Nancy Form and Query are of type dynamic you can access the values using the name of the form or query-string param (see terms and max in the example code). I use a simple base class just to make the syntax terser throughout the rest of my modules.
Note: The ExpandoObject Model in the base class is there so I can just throw values at my view-model and not have to worry about cluttering things up with strongly typed data-transfer classes (this also helps prevent exposing any secret domain instance data).
public class SearchModule : _BaseModule
{
public SearchModule(ISearchService searchService)
{
Get["/search"] = _ =>
{
if (!Query.terms.HasValue) return HttpStatusCode.BadRequest;
var terms = (string) Query.terms;
var max = (Query.max.HasValue) ? (int) Query.max : 3;
Model.SearchResults = searchService.GetResults(max, terms);
...
};
}
}
public class _BaseModule : NancyModule
{
protected dynamic Model = new ExpandoObject();
public dynamic Query { get { return Request.Query; } }
public dynamic Form { get { return Request.Form; } }
}

Resources